#include <iostream>
#include <string>

// 装饰模式
// Person类(ConcreteComponent) 被装饰的类
class Person {
    public:
    Person():name_("无名人士"){}

    Person(std::string name):name_(name){}

    virtual void Show() {
        std::cout << "装扮的" << name_ << std::endl;
    }

    private:
    std::string name_;
};

// 服饰抽象类(Decoator) 装饰抽象类
class Finery : public Person {
    public:
    void Decorate(Person* component) {
        component_ = component;
    }
    virtual void Show() {
        if(component_ != nullptr) {
            component_->Show();
        }
    }
    protected:
    Person* component_;
};

// 具体服饰类(ConcreteDecorator)
class Tshirts : public Finery {
    public:
    virtual void Show() {
        std::cout << "大T恤 ";
        Finery::Show();
    }
};

class BigTrouser : public Finery {
    public:
    virtual void Show() {
        std::cout << "垮裤 ";
        Finery::Show();
    }
};

int main() {
    std::cout << "hello decorative pattern!" << std::endl;
    Person* xc = new Person("小菜");
    Tshirts* Ts = new Tshirts();
    BigTrouser* Bt = new BigTrouser();
    Ts->Decorate(xc);
    Bt->Decorate(Ts);
    Bt->Show();
    delete Ts;
    delete xc;
    delete Bt;
    Ts = nullptr;
    xc = nullptr;
    Bt = nullptr;
    return 0;
}